export function generateDataArray(length: number) {
    const titles = [
        '辣椒生产线',
        '葡萄生产线',
        '中草药生产线',
        '枸杞生产线',
        '方竹笋生产线',
        '红枣生产线'
    ];

    const currentYear = new Date().getFullYear();

    const dataArray = [];
    for (let i = 0; i < length; i++) {
        const randomTitle = titles[Math.floor(Math.random() * titles.length)];
        const randomDay = String(Math.floor(Math.random() * 28) + 1).padStart(2, '0'); // 随机日期
        const key = ["N", "B"][Math.floor(Math.random() * 2)]
        const orderNum = `${currentYear}${key}${randomDay}${i + 1}`; // 生成orderNum
        const percent = Math.floor(Math.random() * (95 - 10)) + 10
        let color;
        if (percent >= 80 && percent <= 95) {
            color = {
                '0%': '#168595',
                '100%': '#24dcf7',
            }
        } else if (percent >= 69 && percent <= 79) {
            color = {
                '0%': '#1f8570',
                '100%': '#3ae5af',
            }
        } else if (percent >= 55 && percent <= 68) {
            color = {
                '0%': '#707732',
                '100%': '#f7c824',
            }
        } else {
            color = undefined
        }
        dataArray.push({
            title: randomTitle,
            orderNum: orderNum,
            color,
            percent,
        });
    }
    // dataArray.sort((a, b) => {
    //     return parseInt(a.orderNum) - parseInt(b.orderNum);
    // });

    // dataArray[0] = Object.assign(dataArray[0], {
    //     percent: 90,
    //     color: {
    //         '0%': '#168595',
    //         '100%': '#24dcf7',
    //     }
    // })
    // dataArray[1] = Object.assign(dataArray[1], {
    //     percent: 80,
    //     color: {
    //         '0%': '#1f8570',
    //         '100%': '#3ae5af',
    //     }
    // })
    // dataArray[2] = Object.assign(dataArray[2], {
    //     percent: 70,
    //     color: {
    //         '0%': '#707732',
    //         '100%': '#f7c824',
    //     }
    // })
    return dataArray;
}

export const getAssetPath = (path: string) => {
    if (path.includes("/carousel-icon/")) {
        return new URL(`/src/assets/carousel-icon/${path.replace("/carousel-icon/", "")}`, import.meta.url).href
    }
    return new URL(`/src/assets/${path}`, import.meta.url).href
}

export function generatePerson(target: "performance" | "order" = "performance") {
    let newData = []
    const baseArray: {
        xm: string;
        bm: string;
        zw?: string;
        xse?: number;
        dataIndex: string;
        goods?: string
        area?: string
        dir?: string
        moneyM?: number
        countM?: number
    }[] = [
            { xm: "唐颖玲", bm: "容太科技", zw: "销售总经理", xse: 2895, dataIndex: "tyl", goods: "小米辣", area: "贵州", dir: "南方", moneyM: 282, countM: 6 },
            { xm: "苏照亮", bm: "容太机械", zw: "销售总经理", xse: 2506, dataIndex: "szl", goods: "红枣", area: "新疆", dir: "北方", moneyM: 0, countM: 0 },
            { xm: "谢在东", bm: "容太机械", zw: "销售经理", xse: 2367, dataIndex: "xzd", goods: "红枣", area: "新疆", dir: "北方", moneyM: 0, countM: 0 },
            { xm: "刘林", bm: "容太科技", zw: "销售总监", xse: 2286, dataIndex: "ll", goods: "八角", area: "广西", dir: "南方", moneyM: 0, countM: 2 },
            { xm: "郭勇胜", bm: "容太机械", zw: "销售经理", xse: 1065, dataIndex: "hl", goods: "枸杞", area: "甘肃", dir: "北方", moneyM: 0, countM: 0 },
            { xm: "李阳升", bm: "容太机械", zw: "销售经理", xse: 1065, dataIndex: "hl", goods: "枸杞", area: "甘肃", dir: "北方", moneyM: 136, countM: 3 },
            { xm: "罗海", bm: "容太科技", zw: "销售经理", xse: 0.89 + 53, dataIndex: "sh", goods: "生姜", area: "云南", dir: "南方", moneyM: 86, countM: 2 },
            { xm: "孙浩", bm: "容太科技", zw: "销售经理", xse: 0.89 + 53, dataIndex: "sh", goods: "生姜", area: "云南", dir: "南方", moneyM: 53, countM: 1 },
            { xm: "卢国靖", bm: "容太科技", zw: "销售经理", xse: 0.88 + 89, dataIndex: "lgj", goods: "生地", area: "四川", dir: "南方", moneyM: 0, countM: 1 },
            { xm: "龚荣", bm: "容太科技", zw: "销售经理", xse: 0.85, dataIndex: "gr", goods: "玉米", area: "河南", dir: "南方", moneyM: 0, countM: 0 },
            { xm: "孟浩", bm: "容太科技", zw: "销售经理", xse: 0.84, dataIndex: "mh", goods: "芦根", area: "河南", dir: "南方", moneyM: 0, countM: 0 },
            { xm: "谢在东", bm: "容太机械", zw: "销售经理", xse: 0.82, dataIndex: "xzd", goods: "红枣", area: "新疆", dir: "北方", moneyM: 0, countM: 0 },
            { xm: "杨丽红", bm: "容太机械", zw: "销售内勤", xse: 0.81, dataIndex: "ylh", goods: "二荆条辣椒", area: "新疆", dir: "北方", moneyM: 0, countM: 0 },
        ]
    for (let i = 0; i < baseArray.length; i++) {
        const id = i + 1
        if (target === "performance") {
            newData.push({
                id,
                ...baseArray[i]
            })
        } else {
            // delete baseArray[i].zw
            // delete baseArray[i].xse
            const res = {
                id,
                bbzs: Math.floor(Math.random() * (350 - 300 + 1)) + 300,
                qd: Math.floor(Math.random() * (280 - 220 + 1)) + 220,
                zzgj: Math.floor(Math.random() * (10 - 6 + 1)) + 6,
            }
            newData.push(Object.assign(res, {
                wx: res.bbzs - res.qd - res.zzgj,
                ...baseArray[i]
            }))
            newData.splice(3)
        }
    }
    return newData
}